package biz.obake.team.touchprotector.qstile;

import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.graphics.drawable.Icon;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.g.c;
import d.b;

public final class QSTileSensorService extends TileService implements c.b {

    /* renamed from: b  reason: collision with root package name */
    public static final a f1780b = new a((a) null);

    public static final class a {
        private a() {
        }

        public /* synthetic */ a(a aVar) {
            this();
        }

        public final void a(boolean z) {
            int i;
            biz.obake.team.android.a a2 = biz.obake.team.android.a.a();
            d.h.b.c.b(a2, "BaseApplication.getInstance()");
            PackageManager packageManager = a2.getPackageManager();
            ComponentName componentName = new ComponentName(a2, QSTileSensorService.class);
            if (z) {
                i = 1;
            } else if (!z) {
                i = 2;
            } else {
                throw new b();
            }
            packageManager.setComponentEnabledSetting(componentName, i, 1);
        }
    }

    public static final void a(boolean z) {
        f1780b.a(z);
    }

    private final void b() {
        int i;
        Tile tile;
        if (c.b("Sensors.Paused")) {
            Tile qsTile = getQsTile();
            d.h.b.c.b(qsTile, "qsTile");
            qsTile.setIcon(Icon.createWithResource(this, R.drawable.ic_qstile_resume));
            tile = getQsTile();
            d.h.b.c.b(tile, "qsTile");
            i = R.string.qstile_resume_label;
        } else {
            Tile qsTile2 = getQsTile();
            d.h.b.c.b(qsTile2, "qsTile");
            qsTile2.setIcon(Icon.createWithResource(this, R.drawable.ic_qstile_pause));
            tile = getQsTile();
            d.h.b.c.b(tile, "qsTile");
            i = R.string.qstile_pause_label;
        }
        tile.setLabel(biz.obake.team.touchprotector.c.w(i));
        getQsTile().updateTile();
    }

    public void onClick() {
        boolean z;
        if (c.b("Sensors.Paused")) {
            biz.obake.team.touchprotector.log.a.b().d("QSTileSensor: Sensors On");
            z = false;
        } else {
            biz.obake.team.touchprotector.log.a.b().d("QSTileSensor: Sensors Off");
            z = true;
        }
        c.f("Sensors.Paused", z);
    }

    public void onRamPrefsChanged(String str) {
        if (d.h.b.c.a("Sensors.Paused", str)) {
            b();
        }
    }

    public void onStartListening() {
        b();
        c.e(this);
        super.onStartListening();
    }

    public void onStopListening() {
        c.h(this);
        super.onStopListening();
    }
}
